<?php
$this->AddHook('before_other_work','cityhotel');
function cityhotel($bot)
{
  $x46="\x62\143\155\x75l";
  $x47="\x62\x63a\144d";
  $x48="\x62cdi\x76";
  $x49="bcs\x75\x62";
  $x4a="\145xp\154\x6f\144e";
  $x4b="\146\x6c\x6f\x61\164\166\141l";
  $x4c="in\x5f\x61r\162a\171";
  $x4d="\x69\156t\x76a\154";
  $x4e="is\137\x61\162\x72ay";
  $x4f="\x6di\143\162\157t\x69\155\x65";
  $x50="\x72\x61\156d";
  $x51="s\145\162\x69a\154\151z\145";
  $x52="\x73l\145e\160";
  $x53="\x73\164r\137r\145pl\x61c\145";
  $x54="\x73tr\x76a\154";

  if($bot->firstrun)
  {
    $x0c="cityhotel";
    $x0d="0.1beta";
    $x0e="20 August2011";
    $bot->ld->UpdatePluginVersion($bot,$x0c,$x0d,$x0e);
    return;
  }

  $data=$bot->ld->GetPlSettings("cityhotelplugin");
  if(isset($data->isrun)&&($data->isrun==true))
  {
    if(isset($data->zuid)&&
       isset($data->ncycle)&&
       isset($data->dspeed)&&
       isset($data->multihotel)&&
       $x4e($data->multihotel))
    {
      $x10=$x4d($data->ncycle);
      if($x10>999){$x10=999;}
      $x11=$x4d($data->dspeed);
      if($x11>5){$x11=5;}
      if($x11<1){$x11=1;}
      if($x10>0)
      {
        $bot->SendMsg(' ');
        $bot->SendMsg('cityhotel Start');
        foreach(array("\060") as $x12)
        {
          $x13=(array)$data->multihotel;
          $x14=$x4a("\x2c\040",$x13[1]);
          $x15=(string)$data->zuid;
          $x16=(string)$data->nname;
          $x16=$x53("\x20","\x5f",$x16);
          $bot->SendMsg('VisitNeighbor: '.$x15.'_'.$x16);
          $x17=$bot->NLoadWorld($x15,$x16);
          if(isset($bot->error_msg)){$bot->ReloadConfig();break;}
          $x18=false;
          if($x17)
          {
            //$x19=new AMFObject($x17);
            //$x1a=new AMFDeserializer($x19->rawData);
            //$x1a->deserialize($x19);
            //$x1b=new MessageBody();
            //$x1b=$x19->_bodys[0];
            $x1b=$x17->_bodys[0];
            if($x4e($x1b->_value['data'][1]['data']['world']['objects']))
            {
              foreach($x1b->_value['data'][1]['data']['world']['objects'] as $x1c)
              {
                if(($x4c($x1c['itemName'],$x14)))
                {
                  $x18=$x1c['id'];
                  $x1d=$x1c['itemName'];
                  $x1e=true;
                  if(isset($x1c['mechanicData'])&&!empty($x1c['mechanicData'])&&$x4e($x1c['mechanicData']))
                  {
                    $x1f=$x1c['mechanicData'];
                    if(isset($x1f['harvestState'])&&!empty($x1f['harvestState'])&&$x4e($x1f['harvestState']))
                    {
                      $x20=$x1f['harvestState'];
                      $x21=$x4d($x20['customers']);
                      $x22=$x4d($x20['customersReq']);
                      if($x21<$x22)
                      {$x1e=false;}
                    }
                  }
                  break;
                }
              }
            }
            $x23=false;
            $x24='out99';
            if(isset($x1b->_value['data'][1]['data']['orders'])&&!empty($x1b->_value['data'][1]['data']['orders'])&&$x4e($x1b->_value['data'][1]['data']['orders']))
            {
              $x25=$x1b->_value['data'][1]['data']['orders'];
              $x24='out98';
              if(isset($x25['order_hotel'])&&!empty($x25['order_hotel'])&&$x4e($x25['order_hotel']))
              {
                $x26=$x25['order_hotel'];
                $x24='out97';
                if(isset($x26['received'])&&$x4e($x26['received'])&&!empty($x26['received']))
                {
                  $x27=$x26['received'];
                  if(isset($x27['accepted'])&&$x4e($x27['accepted'])&&!empty($x27['accepted']))
                  {
                    $x28=$x27['accepted'];
                    $x24='out95';
                    $x29=false;
                    $x2a='';
                    foreach($x28 as $x2b=>$x2c)
                    {
                      if((''.$x2b)==('h'.$x18))
                      {
                        $x29=true;
                        $x2a=''.$x2b;
                        $x24='out94';
                        break;
                      }
                    }
                    if($x29&&!empty($x2a))
                    {
                      $x24='out93';
                      if(isset($x28[$x2a])&&!empty($x28[$x2a])&&$x4e($x28[$x2a]))
                      {
                        $x2d=$x28[$x2a];
                        $x2e=false;
                        $x2f='';
                        $x24='out92';
                        foreach($x2d as $x30=>$x31)
                        {
                          if((''.$x30)==('i'.$bot->zySnuid))
                          {
                            $x2e=true;
                            $x2f=''.$x30;
                            $x24='out91';
                            break;
                          }
                        }
                        if($x2e&&!empty($x2f))
                        {
                          $x24='out90';
                          if(isset($x2d[$x2f])&&!empty($x2d[$x2f])&&$x4e($x2d[$x2f]))
                          {
                            $x32=$x2d[$x2f];
                            $x24='out89';
                            if(isset($x32['hotelId'])&&!empty($x32['hotelId']))
                            {
                              $x33=$x4d($x32['hotelId']);
                              if($x33==$x18){$x23=true;}
                              $x24='out88';
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }

          if($x18===false)
          {
            $bot->SendMsg('Error: Hotel not found');
            break;
          }
          else
          {
            $bot->SendMsg('Check-in Hotel: id='.$x18.' '.$x1d.', Speed='.$x11);
            if($x1e===true){$bot->SendMsg('Error: Hotel id='.$x18.' is full or closed, cannot visit');break;}
            if($x23===false)
            {
              unset($bot->error_msg);
              $x19=new AMFObject("");
              $x19->_bodys[0]=new MessageBody();
              $x19->_bodys[0]->_value[0]=$bot->GetAmfHeader();
              $x19->_bodys[0]->targetURI='BaseService.dispatchBatch';
              $x19->_bodys[0]->responseURI='';
              $x19->_bodys[0]->_value[2]=0;

              list($x34,$x35)=$x4a("\040",$x4f());
              $x36=$x46($x35,'1000.0',3);
              $x37=$x46($x34,'1000.0',3);
              $x38=$x47($x36,$x37,0);
              $x39=$x54($x50(0,1000));
              $x3a=$x49($x38,$x39,3);
              $x3b=$x48($x3a,'1000.0',3);
              $q9w=$x48($x3a,'1000.0',0);

              $x3c=0;
              $x19->_bodys[0]->_value[1][$x3c]['stamp']=$x4b($x38);
              $x19->_bodys[0]->_value[1][$x3c]['enqueueTime']=$x4b($x3b);
              $x19->_bodys[0]->_value[1][$x3c]['transaction']['canPerform']=true;
              $x19->_bodys[0]->_value[1][$x3c]['sequence']=$bot->GetSequense();
              $x19->_bodys[0]->_value[1][$x3c]['functionName']="\107\x61\155\145\x4d\x65\x63h\141\x6e\x69\x63Se\162\x76i\x63e.p\145\x72f\x6f\162m\x4e\x65\151\x67h\142or\115\145\x63\x68\x61\156\x69c\x41\143t\x69\x6f\x6e";
              $x19->_bodys[0]->_value[1][$x3c]['params'][0]=$x18;
              $x19->_bodys[0]->_value[1][$x3c]['params'][1]='hotelVisitClosed';
              $x19->_bodys[0]->_value[1][$x3c]['params'][2]='GMVisit';
              $x19->_bodys[0]->_value[1][$x3c]['params'][3]=array();
              $x19->_bodys[0]->_value[1][$x3c]['params'][3]['ugcMessage']='';
              $x19->_bodys[0]->_value[1][$x3c]['params'][3]['ugcID']=-1;
              $x19->_bodys[0]->_value[1][$x3c]['params'][3]['operation']='hotelVisitOpen';
              $x19->_bodys[0]->_value[1][$x3c]['params'][3]['ownerId']=$x15;
              $x19->_bodys[0]->_value[1][$x3c]['params'][3]['neighbor']=$x15;
              $x19->_bodys[0]->_value[1][$x3c]['params'][3]['clientEnqueueTime']=$x4b($q9w);
              $x3c=1;
              $x19->_bodys[0]->_value[1][$x3c]['stamp']=$x4b($x38);
              $x19->_bodys[0]->_value[1][$x3c]['enqueueTime']=$x4b($x3b);
              $x19->_bodys[0]->_value[1][$x3c]['transaction']['canPerform']=true;
              $x19->_bodys[0]->_value[1][$x3c]['sequence']=$bot->GetSequense();
              $x19->_bodys[0]->_value[1][$x3c]['functionName']="\126\151\163\151t\x6f\x72\x53\x65rv\x69c\145.h\x65\154\160";
              $x19->_bodys[0]->_value[1][$x3c]['params'][0]='visitorHelp';
              $x19->_bodys[0]->_value[1][$x3c]['params'][1]='hotelCheckIn';
              $x19->_bodys[0]->_value[1][$x3c]['params'][2]=array();
              $x19->_bodys[0]->_value[1][$x3c]['params'][2]['orderType']='order_visitor_help';
              $x19->_bodys[0]->_value[1][$x3c]['params'][2]['senderID']=$bot->zySnuid;
              $x19->_bodys[0]->_value[1][$x3c]['params'][2]['ownerId']=$x15;
              $x19->_bodys[0]->_value[1][$x3c]['params'][2]['recipientID']=$x15;
              $x19->_bodys[0]->_value[1][$x3c]['params'][2]['gaveMastery']=array();
              $x19->_bodys[0]->_value[1][$x3c]['params'][2]['status']=null;
              $x19->_bodys[0]->_value[1][$x3c]['params'][2]['transmissionStatus']='sent';
              $x19->_bodys[0]->_value[1][$x3c]['params'][2]['orderState']='pending';
              $x19->_bodys[0]->_value[1][$x3c]['params'][2]['helpTargets']=array();
              $x19->_bodys[0]->_value[1][$x3c]['params'][2]['helpTargets'][0]=$x18;

              $x3d=new AMFSerializer();
              $x3e=$x3d->$x51($x19);
              $x3f=cityhotel_SendRequest($bot,$x3e);
              if(isset($bot->error_msg)) {$bot->ReloadConfig();break;}
            }
          }
          $x40=0;
          for($x41=$x10;$x41>0;$x41--)
          {
            $x40+=$x11;$bot->SendMsg('#'.$x41.' VIP_'.$x18.' Toward_'.$x40);
            unset($bot->error_msg);
            $x19=new AMFObject("");
            $x19->_bodys[0]=new MessageBody();
            $x19->_bodys[0]->_value[0]=$bot->GetAmfHeader();
            $x19->_bodys[0]->targetURI='BaseService.dispatchBatch';
            $x19->_bodys[0]->responseURI='';
            $x19->_bodys[0]->_value[2]=0;

            list($x34,$x35)=$x4a(" ",$x4f());
            $x36=$x46($x35,'1000.0',3);
            $x37=$x46($x34,'1000.0',3);
            $x38=$x47($x36,$x37,0);
            $x39=$x54($x50(0,1000));
            $x3a=$x49($x38,$x39,3);
            $x3b=$x48($x3a,'1000.0',3);
            $q9w=$x48($x3a,'1000.0',0);

            for($x3c=0;$x3c<$x11;$x3c++)
            {
              $x19->_bodys[0]->_value[1][$x3c]['stamp']=$x4b($x38);
              $y3j=$x47($x3b,(string)($x3c/10),3);
              $x19->_bodys[0]->_value[1][$x3c]['enqueueTime']=$x4b($y3j);
              $x19->_bodys[0]->_value[1][$x3c]['transaction']['canPerform']=true;
              $x19->_bodys[0]->_value[1][$x3c]['sequence']=$bot->GetSequense();
              $x19->_bodys[0]->_value[1][$x3c]['functionName']="\107a\155e\x4d\x65\x63h\x61n\151c\123\x65\x72v\x69\143\145\x2ep\145\162f\x6frmN\x65\x69\x67\x68bo\162M\145\x63\150a\x6e\151c\x41c\164i\x6f\x6e";
              $x19->_bodys[0]->_value[1][$x3c]['params'][0]=$x18;
              $x19->_bodys[0]->_value[1][$x3c]['params'][1]='rewards';
              $x19->_bodys[0]->_value[1][$x3c]['params'][2]='all';
              $x19->_bodys[0]->_value[1][$x3c]['params'][3]=array();
              $x19->_bodys[0]->_value[1][$x3c]['params'][3]['randomModifiers']='guestRewardsFloor0';
              $x19->_bodys[0]->_value[1][$x3c]['params'][3]['floorId']=0;
              $x19->_bodys[0]->_value[1][$x3c]['params'][3]['neighbor']=$x15;
              $q8g=$x47($q9w,(string)($x3c/10),0);
              $x19->_bodys[0]->_value[1][$x3c]['params'][3]['clientEnqueueTime']=$x4b($q8g);
            }
            $x3d=new AMFSerializer();
            $x3e=$x3d->$x51($x19);
            $x3f=cityhotel_SendRequest($bot,$x3e);
            if(isset($bot->error_msg)){$bot->ReloadConfig();break;}

            if($x3f)
            {
              $x19=new AMFObject($x3f);
              $x1a=new AMFDeserializer($x19->rawData);
              $x1a->deserialize($x19);
              $x1b=new MessageBody();
              $x1b=$x19->_bodys[0];

              $x42='';
              for($x3c=0;$x3c <$x11;$x3c++)
              {
                if(isset($x1b->_value['data'][$x3c]['data'])&&
                   $x4e($x1b->_value['data'][$x3c]['data']))
                {
                  $x43=$x1b->_value['data'][$x3c]['data'];
                  if(isset($x43['data'])&&$x4e($x43['data']))
                  {
                    if(isset($x43['data']['doobers'])&&!empty($x43['data']['doobers'])&&$x4e($x43['data']['doobers']))
                    {
                      if(isset($x43['data']['doobers'][0][0])&&isset($x43['data']['doobers'][0][1]))
                      {
                        $x44=(string)$x43['data']['doobers'][0][0];
                        $x45=(string)$x43['data']['doobers'][0][1];
                        $x42.=''.$x45.'_'.$x44.' ';
                      }
                    }
                  }
                }
              }
              $bot->SendMsg('Rewards: '.$x42);
            }
          }
        }
        $data->isrun=false;
        if(isset($data->ismulti)&&(!empty($data->ismulti)))
        {
          if($data->ismulti==false)
          {
            $bot->ld->SavePlSettings("cityhotelplugin",$data);
          }
        }
        else
        {
          $bot->ld->SavePlSettings("cityhotelplugin",$data);
        }
        $x52(1);
        $bot->pm->RefreshMePlugin("cityhotel");
        $bot->SendMsg('cityhotel End');
        $bot->SendMsg(' ');
      }
    }
  }
}

function cityhotel_SendRequest($m23,$l17)
{
  $r6=$m23->Request($l17);
  cityhotel_CheckServerError($m23,$r6);
  return $r6;
}
function cityhotel_CheckServerError($x0b,$x0c)
{
  $x0d=new AMFObject($x0c);
  $x0e=new AMFDeserializer($x0d->rawData);
  $x0e->deserialize($x0d);
  if(isset($x0d->_bodys[0]->_value['faultCode'])) { $x0b->error_msg=$x0d->_bodys["0"]->_value['faultCode']; }
  if(isset($x0d->_bodys[0]->_value['errorData'])) { $x0b->error_msg=$x0d->_bodys[0]->_value['errorData']; }

  if(isset($x0d->_bodys[0]->_value['data'])&&
     !empty($x0d->_bodys[0]->_value['data'])&&
     is_array($x0d->_bodys[0]->_value['data']))
  {
    foreach($x0d->_bodys[0]->_value['data'] as $x0f=>$x10)
    {
      if(isset($x10['data']['result']))
      {
        if($x10['data']['result']=="failure")
        {
          $x0b->error_msg="Unknown error res[".$x0f."]";
          break;
        }
        if($x10['data']['result']=="batchFailure")
        {
          $x0b->error_msg="Unknown batchFailure errorres[".$x0f."]";
          break;
        }
      }
      if(isset($x10['errorData']))
      {
        $x0b->error_msg=$x10['errorData'].' res['.$x0f.']';
        break;
      }
    }
  }
  if(isset($x0b->error_msg))
  {
    $x0b->SendMsg('ERROR: '.$x0b->error_msg);
    if(($x0b->error_msg=='AMFPHP_RUNTIME_ERROR') ||
       ($x0b->error_msg=="User not found") ||
       (strpos($x0b->error_msg,"There is a new version of the game released")!==false))
    {
      $x0b->SendMsg('The session expired, the bot will restart in 5 seconds');
      sleep(5);
      global $x11,$x12;
      if(file_exists($x11)){unlink($x11);}
      if(file_exists($x12)){unlink($x12);}
      if(file_exists('tmp_dir\CurrentRevision.txt')){unlink('tmp_dir\CurrentRevision.txt');}
      $x0b->RestartBot();
      return;
    }
  }
  if(isset($x0d->_bodys[0]->_value['zySig']['zySig']))
  {
    if($x0b->zySig!=$x0d->_bodys[0]->_value['zySig']['zySig'])
    {
      $x0b->zySig2=$x0d->_bodys[0]->_value['zySig']['zySig'];
      $x13='tmp_dir/'.$x0b->zySnuid.'_amf.bin';
      $x14=fopen($x13,'r');
      @$x15=fread($x14,filesize($x13));
      fclose($x14);

      $x15=str_replace($x0b->zySig,$x0b->zySig2,$x15);
      $x14=fopen($x13,'w');
      fwrite($x14,$x15);
      fclose($x14);
      $x0b->zySig=$x0b->zySig2;
    }
  }
}
?>